﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
namespace gamexpert.admin
{
    public partial class Enquiries : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!(User.Identity.IsAuthenticated && User.IsInRole("Administrator")))
            {
                Response.Redirect("~/admin/Default.aspx");
            }
            LinkButton lb = (LinkButton)Master.FindControl("lbtn_enquiries");
            lb.CssClass = "selected";
        }

        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            
        }

     
        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            //MultiView1.ActiveViewIndex = 1;
        }

        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            //DataTable toExcel = formattedDataTable.Copy();
            DataSet1 ds = new DataSet1();
            DataSet1TableAdapters.my_enquiryTableAdapter da = new DataSet1TableAdapters.my_enquiryTableAdapter();
            da.Fill(ds.my_enquiry);
            DataTable toExcel = ds.my_enquiry;
            HttpContext context = HttpContext.Current;
            context.Response.Clear();

            foreach (DataColumn column in toExcel.Columns)
            {
                context.Response.Write(column.ColumnName + ",");
            }

            context.Response.Write(Environment.NewLine);
            foreach (DataRow row in toExcel.Rows)
            {
                for (int i = 0; i < toExcel.Columns.Count; i++)
                {
                    context.Response.Write(row[i].ToString().Replace(",", string.Empty) + ",");
                }

                context.Response.Write(Environment.NewLine);
            }

            context.Response.ContentType = "text/csv";
            context.Response.AppendHeader("Content-Disposition", "attachment; filename=Enquiries_" + DateTime.Now.ToShortDateString() + ".csv");
            context.Response.End();
        }
    }
}
